import json

from api import midjourney_operation


def prompt2img(prompt):
    task=midjourney_operation.submit_midjourney_task(prompt)
    #从json中data中获取taskId
    taskId=json.loads(task)['data']['taskId']

    #循环获取图片信息，直到图片生成
    while True:
        task_info=midjourney_operation.get_midjourney_task_info(taskId)
        task_info=json.loads(task_info)
        print(task_info)
        if task_info['data']['taskStatus']==30: #任务状态，10=排队等待，20=正在执行，30=成功，40=失败
            return task_info['data']['imageUrl'],taskId
        else:
            continue
    return task_info['data']['imageUrl'],taskId
